/*!
 * Ext JS Library 3.3.0
 * Copyright(c) 2006-2010 Ext JS, Inc.
 * licensing@extjs.com
 * http://www.extjs.com/license
 */
 
function mes(mes) {
	var  m = parseInt(mes);
	switch(m) {
		case 1:
			return 'Ene'
		case 2:
			return 'Feb'
		case 3:
			return 'Mar'
		case 4:
			return 'Abr'
		case 5:
			return 'May'
		case 6:
			return 'Jun'
		case 7:
			return 'Jul'
		case 8:
			return 'Ago'
		case 9:
			return 'Sep'
		case 10:
			return 'Oct'
		case 11:
			return 'Nov'
		case 12:
			return 'Dic'
		default:
			return 'Unk'
	}
}

Ext.chart.Chart.CHART_URL = '../js/ext/resources/charts.swf';

Ext.onReady(function(){

	$.getJSON("select-grafico1.php", {ano: 2011}, function(data) {
	
		arrData = data;

		store = new Ext.data.JsonStore({
			fields:['MES', 'CONT'],
			data: data
		});
		
		var anoCombo = new Ext.form.ComboBox({
			width: 200,
			typeAhead: true,
			triggerAction: 'all',
			lazyRender:true,
			mode: 'local',
			forceSelection: true,
			store: new Ext.data.ArrayStore({
				id: 0,
				fields: [
					'id',
					'displayText'
				],
				data: [[1, '2011'], [2, '2012'], [3, '2013'], [4, '2014'], [5, '2015'],
				       [6, '2016'], [7, '2017'], [8, '2018'], [9, '2019'], [10, '2020']]
			}),
			listeners: {
				select: function(combo, record, index) {
					$.getJSON("select-grafico1.php", {ano: 2011}, function(data) {
						store.loadData(data, false);
					});
					//alert("select");
					//store.loadData(filtrar(arrData, parseInt(record.data.displayText)), false);
					//g1.bindStore(store);
				}
			},
			valueField: 'id',
			displayField: 'displayText'
		});
		anoCombo.setValue('2011');
		
		g1 = new Ext.Panel({
			title: 'ExtJS.com Visits Trend, 2007/2008 (No styling)',
			width:500,
			height:300,
			layout:'fit',
			items: {
				xtype: 'columnchart',
				store: store,
				yField: 'MES',
				store: store,
				listeners: {
					itemclick: function(o){
						var rec = store.getAt(o.index);
						Ext.example.msg('Item Selected', 'You chose {0}.', rec.get('name'));
					}
				},
				series: [{
					xField: 'CONT',
					displayName: 'Consultas'
				}]
			}
		});
		
		grafico1 = new Ext.Panel({
			layout: 'fit',
			items: [
				anoCombo, g1
			]
		});
	});
});